home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / comm / irc / epic4-mos.lha / share / epic / script / files < prev    next >
Text File  |  2002-09-18  |  1KB  |  62 lines

  1. /*
  2.  * FILES script -- complements the new file functions.
  3.  * Written by Jeremy Nelson -- EPIC project
  4.  *
  5.  * These aliases are not anywhere near as fast as /exec'ing the
  6.  * c programs, but they are here to illustrate the usage of the fns.
  7.  */
  8.  
  9. /* dump a file out to the screen w/o using /exec */
  10. alias cat {
  11.     @ fd = open($0 R)
  12.     while (!eof($fd)) { echo $read($fd) }
  13.     @ close($fd)
  14. }
  15.  
  16. /* Search for a string in a group of files */
  17. /* This is, of course, case insensitive */
  18. alias grep {
  19.     for x in ($1-) {
  20.         @ fd = open($x R)
  21.         while (!eof($fd)) { 
  22.             @ line = read($fd)
  23.             if (match(*$0* $line))
  24.                 {echo $x: $line}
  25.         }
  26.         @close($fd)
  27.     }
  28. }
  29.  
  30. /* Write a line to a file w/o using the logging features */
  31. alias log_it {
  32.     @ fd = open($0 W)
  33.     @ write($fd $1-)
  34.     @ close($fd)
  35. }
  36.  
  37. # Call as /exclude filename pattern
  38. #
  39. alias exclude { 
  40.         @ :reg = regcomp($1-)
  41.         @ :rd = open($0 R)
  42.         @ :wd = open($0.new W)
  43.         
  44.     @ line = read($rd)
  45.     do
  46.         {       
  47.                 if (regexec($reg $line)) {
  48.                         @ write($wd $line)
  49.                 }
  50.         @ line = read($rd)
  51.         } while (!eof($rd))
  52.  
  53.         @ close($rd)
  54.         @ close($wd)
  55.         @ regfree($reg)
  56.                        
  57.         @ unlink($0)
  58.         @ rename($0.new $0)
  59. }                          
  60.  
  61.